Ninja Database Pro
Delete<T>(T) Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class > Delete Method : Delete<T>(T) Method
Delete a specific object from the database The object must have a primary key property of Id or ObjectNameId as a type of long or an exception will be thrown. Example primary key: CustomerId
Syntax
Public Overloads Function Delete(Of T As {Class, New})( _
   ByVal row As T _
) As Integer
Dim instance As NinjaDbPro
Dim row As T
Dim value As Integer
 
value = instance.Delete(Of T)(row)
public int Delete<T>( 
   T row
)
where T: class, new()
public:
int Deletegeneric<typename T>
( 
   T^ row
) 
where T: ref class, gcnew()

Parameters

row

Type Parameters

T

Return Value

Number of items deleted
Example
NinjaDbPro db = new NinjaDbPro("MyDatabaseDirectory", "MyDatabaseName");
             
            //Licensed Mode
            //db.UserName = "John Smith 101224";
            //db.LicenseKey = "aousdf832jasf==";
             
            //Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
            //db.Storage = new MemoryDatabase(); //In memory database
            //db.Storage = new FileDatabase();  
             
            db.OpenDatabase();
             
            Person person = new Person();
            person.Name = "John Smith";
             
            //Save it
            db.Save(person);
             
            //Delete it
            int recordsDeleted = db.Delete(person);
             
            db.CloseDatabase();
Dim db As New NinjaDbPro("MyDatabaseDirectory", "MyDatabaseName")
             
            'Licensed Mode
            'db.UserName = "John Smith 101224";
            'db.LicenseKey = "aousdf832jasf==";
             
            'Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
            'db.Storage = new MemoryDatabase(); //In memory database
            'db.Storage = new FileDatabase();  
             
            db.OpenDatabase()
             
            Dim person As New Person()
            person.Name = "John Smith"
             
            'Save it
            db.Save(person)
             
            'Delete it
            Dim recordsDeleted As Integer = db.Delete(person)
             
            db.CloseDatabase()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

NinjaDbPro Class
NinjaDbPro Members
Overload List